package com.zsrt.java.day20161223.lh.homework1223.Demo06;

import static org.junit.Assert.*;

import java.util.Scanner;

import org.junit.Test;

public class calSwitch {
	/**
	 * 用switch语法完成： 加减乘除求模的计算器 
	 */
	@Test
	public void switch01() throws Exception {
		//从键盘输入数
		Scanner sc=new Scanner(System.in);
		System.out.println("输入数：");
		int a=sc.nextInt();
		System.out.println("输入符号比如+-*%/：");
		String c=sc.next();
		System.out.println("输入数：");
		int b=sc.nextInt();
		sc.close();
		System.out.println("a="+a+"\t"+"b="+b);
		//判断符号运算
		switch (c) {
		case "-": System.out.println("a-b="+(a+(-b)));	break;
		case "+": System.out.println("a+b="+(a+b));	break;
		case "*": System.out.println("a*b="+a*b);	break;
		case "/": System.out.println("a/b="+a/b);	break;
		case "%": System.out.println("a%b="+a%b);	break;
		default:System.out.println("请正确输入");		break;
		}
	}
	/**
	 * 用if(){}else语法完成： 加减乘除求模的计算器 
	 * @throws Exception
	 */
	@Test
	public void ifelse01() throws Exception {
		//从键盘输入数
		Scanner sc=new Scanner(System.in);
		System.out.println("输入数：");
		int a=sc.nextInt();
		System.out.println("输入符号比如+-*%/：");
		String c=sc.next();
		System.out.println("输入数：");
		int b=sc.nextInt();
		sc.close();
		System.out.println("a="+a+"\t"+"b="+b);
		
		//判断运算符运算
		if("-".equals(c)){
			System.out.println("a-b="+(a+(-b)));
		}else if("+".equals(c)){
			System.out.println("a+b="+(a+b));
		}else if("*".equals(c)){
			System.out.println("a*b="+a*b);
		}else if("/".equals(c)){
			System.out.println("a%b="+a/b);
		}else if("%".equals(c)){
			System.out.println("a%b="+a%b);
		}else{
			System.out.println("请正确输入");
		}
	}

}
